/**
 * 获取url中的参数
 */
export const getQueryString = (name: string) => {
  const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  const r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
};

type JarvisModName = 'portal' | 'ds' | 'task' | 'message';
const getJarvisModName = (pathname: string): JarvisModName => {
  const modName = (pathname.split('/')[1] || 'portal') as JarvisModName;
  // 未拆分出来的模块, 统一用portal
  return ['authmanage'].includes(modName) ? 'portal' : modName;
};

export const quit = () => {
  const modName = getJarvisModName(location.pathname);
  const currUrl = location.href.split('#')[0];
  const nextUrl = `/${modName}/fjarvisxLogin?redirectUrl=${currUrl}`;
  window.location.href = nextUrl;
};
